<?php
/**
 * Created by PhpStorm.
 * User: yzh
 * Date: 2019/5/11
 * Time: 15:58
 */

namespace app\api\model;



class PosterMaterial extends  BaseModel
{
    protected $autoWriteTimestamp = true;

    protected $hidden = ['create_time','update_time'];
    /**
     * 与posterclass为1对1关系
     * @return \think\model\relation\BelongsTo
     */
    public  function category(){
        return $this->belongsTo('PosterClass','style','id');
    }

    /**
     * 与attachment多对一关系
     * @return \think\model\relation\BelongsTo
     */
    public function image(){
        return $this->belongsTo('AdminAttachment','attachment_id','id');
    }

    /**
     * 获取所有名片id
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getPosterID(){
        return self::where('1=1')->field(['id'])->select();
    }

    /**
     * 浏览次数递增
     * @param $id
     * @return int|true
     * @throws \think\Exception
     */
    public static function addUsedNum($id){
        return self::where('id','=',$id)->setInc('userd');
    }

    /**
     * 根据名片id获取名片
     * @param $ids
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function  getPosterByIds($ids){
        return self::where('id','in',$ids)->with(['image'])->select();
    }

    /**
     * 获取海报列表
     * @param $style
     * @param $size
     * @param $page
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public static function  getPosterByClass($style,$size,$page){
       return self::where('status = 1')
            ->where('style','=',$style)->with(['image'])->with(['category'])->order('create_time','desc')
            ->paginate($size,false,['page'=>$page]);

    }



}